/**
 * SeamtWebApplicationInitializer.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2014年10月22日
 */
package com.pshare.framework.web;

import javax.servlet.Filter;
import javax.servlet.ServletRegistration;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import com.pshare.framework.filter.InputFilter;
import com.pshare.framework.filter.xss.XSSSecurityFilter;

/**
 * 容器配置管理
 * 代替web.xml
 */
public abstract class SeamtWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
	
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
 
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] {};
    }
 
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        
        XSSSecurityFilter xssSecurityFilter = new XSSSecurityFilter();

        InputFilter inputFilter = new InputFilter();

        return new Filter[] {characterEncodingFilter, xssSecurityFilter, inputFilter};
    }
 
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {        
        registration.setInitParameter("spring.profiles.active", "default");
        registration.setInitParameter("contextConfigLocation", "classpath:/applicationContext.xml");
    }

}
